//
//  CalendarViewController.m
//  hospitalVIP
//
//  Created by xiaoyan on 14-1-14.
//  Copyright (c) 2014年 MEETStudio. All rights reserved.
//

#import "CalendarViewController.h"
#import "ITTBaseDataSourceImp.h"

#import "WeekDetailViewController.h"

@interface CalendarViewController ()

@end

@implementation CalendarViewController
- (IBAction)showCalendar:(id)sender
{
    if (_calendarView.appear)
    {
        [_calendarView hide];
    }
    else
    {
        [_calendarView showInView:self.view];
    }
}
- (NSString*) stringFromFomate:(NSDate*) date formate:(NSString*)formate
{
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:formate];
	NSString *str = [formatter stringFromDate:date];
	[formatter release];
	return str;
}
- (void)calendarViewDidSelectDay:(ITTCalendarView*)calendarView calDay:(ITTCalDay*)calDay
{
    NSArray *selectedDates = calendarView.selectedDateArray;
//    if (calendarView.allowsMultipleSelection)
//    {
//        for (NSDate *date in selectedDates)
//        {
//            NSLog(@"selected date %@", [self stringFromFomate:date formate:@"yyyy-MM-dd"]);
//        }
//    }
//    else
//    {
//       
//    }
    
    WeekDetailViewController *viewContro = [[WeekDetailViewController alloc]init];
    [self.navigationController pushViewController:viewContro animated:YES];
    [viewContro release];
    
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    _calendarView = [ITTCalendarView viewFromNib];
    ITTBaseDataSourceImp *dataSource = [[ITTBaseDataSourceImp alloc] init];
    _calendarView.date = [NSDate dateWithTimeIntervalSinceNow:2*24*60*60];
    _calendarView.dataSource = dataSource;
    _calendarView.delegate = self;
    _calendarView.frame = CGRectMake(8, 40, 309, 410);
    _calendarView.allowsMultipleSelection = TRUE;
    [_calendarView showInView:self.view];
    [dataSource release];
    UIButton *leftBt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [leftBt setImage:[UIImage imageNamed:@"icon_return.png"] forState:UIControlStateNormal];
    [leftBt addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:leftBt];
    [self.navigationItem setLeftBarButtonItem:leftButton];
    [leftBt release];
    [leftButton release];
    
    
}
- (void)backAction:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
